package com.shen.nettysocketchat.bean

import com.shen.nettysocketchat.utils.StringUtil
import java.lang.NullPointerException

/**
 * 消息基类
 */
open class BaseMessage {
    /** 消息·id */
    @JvmField
    var msgId: String? = null
    /** 消息·类型 */
    @JvmField
    var msgType = 0
    /** 消息·内容类型 */
    @JvmField
    var msgContentType = 0

    /** 发送者id */
    @JvmField
    var fromId: String? = null
    /** 接收者id */
    @JvmField
    var toId: String? = null
    /** 消息时间戳 */
    @JvmField
    var timestamp: Long = 0
    /** 消息状态报告 */
    @JvmField
    var statusReport= 0
    /** 扩展字段，以key/value形式存放json */
    @JvmField
    var extend: String? = null
    /** 消息内容 */
    @JvmField
    var content: String? = null

    override fun hashCode(): Int {
        try {
            return msgId.hashCode()
        } catch (e: NullPointerException) {
            e.printStackTrace()
        }
        return 1
    }

    override fun equals(obj: Any?): Boolean {
        return if (obj == null || obj !is BaseMessage) {
            false
        } else StringUtil.equals(msgId, obj.msgId)
    }

}